package pro.shushi.pamirs.hr.api.model.biz;

import pro.shushi.pamirs.boot.base.ux.annotation.field.UxWidget;
import pro.shushi.pamirs.boot.base.ux.annotation.view.UxDetail;
import pro.shushi.pamirs.boot.base.ux.annotation.view.UxForm;
import pro.shushi.pamirs.boot.base.ux.annotation.view.UxTableSearch;
import pro.shushi.pamirs.hr.api.enums.ApprovalStatusEnum;
import pro.shushi.pamirs.hr.api.enums.OneWayReturnEnum;
import pro.shushi.pamirs.hr.api.enums.TransportationEnum;
import pro.shushi.pamirs.hr.api.model.org.Employee;
import pro.shushi.pamirs.meta.annotation.Field;
import pro.shushi.pamirs.meta.annotation.Model;
import pro.shushi.pamirs.meta.base.common.CodeModel;
import pro.shushi.pamirs.meta.enmu.DateFormatEnum;
import pro.shushi.pamirs.meta.enmu.DateTypeEnum;
import pro.shushi.pamirs.meta.enmu.NullableBoolEnum;

import java.util.Date;
import java.util.List;

/**
 * BusinessTrip 出差申请
 *
 * @author shushi
 *
 * 序列(自动生成编码)的定义参考：https://doc.oinone.top/oio4/9236.html
 */
// 模型中UX开头的注解(UxForm/UxTable/UxDetail等)可以不用写，都可在设计器中进行可视化配置; 代码里面写这些注解是为了默认页面的交互
@UxForm(grid = 3)
@UxDetail(grid = 3)
@Model.model(BusinessTrip.MODEL_MODEL)
@Model(displayName = "出差申请", labelFields = "title")
@Model.Code(sequence = "SEQ", prefix = "T", size = 5, step = 2, initial = 10000)
public class BusinessTrip extends CodeModel {

    public static final String MODEL_MODEL = "hr.simple.BusinessTrip";

    @UxTableSearch.FieldWidget(@UxWidget())
    @UxForm.FieldWidget(@UxWidget(readonly = "true", hint = "为空时自动生成"))
    @Field(displayName = "申请单号", unique = true)
    private String code;

    @UxTableSearch.FieldWidget(@UxWidget())
    @Field(displayName = "出差员工", required = true)
    private String employName;

    @UxTableSearch.FieldWidget(@UxWidget())
    @Field.many2one
    @Field.Relation(relationFields = "projectCode", referenceFields = "projectCode")
    @Field(displayName = "所属项目", required = true)
    private ProjectInfo project;

    @Field(displayName = "所属项目编码", invisible = true)
    private String projectCode;

    @Field(displayName = "出差事项", required = true)
    private String title;

    @Field(displayName = "出差事由")
    private String businessReason;

    @Field.Enum
    @Field(displayName = "交通方式", required = true)
    private TransportationEnum transportation;

    @Field.Enum
    @Field(displayName = "单程往返", required = true)
    private OneWayReturnEnum oneWayReturn;

    @Field(displayName = "出发地（城市）", required = true)
    private String startCity;

    @Field(displayName = "目的地（城市）", required = true)
    private String targetCity;

    @Field.Date(type = DateTypeEnum.DATE, format = DateFormatEnum.DATE)
    @Field(displayName = "开始时间", required = true)
    private Date startTime;

    @Field.Date(type = DateTypeEnum.DATE, format = DateFormatEnum.DATE)
    @Field(displayName = "结束时间", required = true)
    private Date endTime;

    /**
     * 字段序列化参考：https://doc.oinone.top/oio4/9238.html
     *
     * 模型中UX相关的注解都可以不用写，Ux相关的配置都可以在设计器中进行可视化配置.
     *    这里加widget = "Select"是让默认的页面同行人交互为下拉多选的方式
     *
     * 特别说明：并不是one2many都需要指定Widget=Select，是目前这个页面让one2many的交互为下拉多选才需要指定
     *         one2many默认是表格的形式，参考：pro.shushi.pamirs.hr.api.model.org.Department#positions
     */
    @UxForm.FieldWidget(@UxWidget(widget = "Select"))
    @UxDetail.FieldWidget(@UxWidget(widget = "Select"))
    @Field.one2many
    @Field(displayName = "同行人(非离职)", serialize = Field.serialize.JSON, store = NullableBoolEnum.TRUE)
    @Field.Relation(domain = "employeeStatus !='3'", store = false)
    @Field.Advanced(columnDefinition = "TEXT")
    private List<Employee> txEmployee;

    /**
     * 枚举的defaultValue需要用枚举的name。
     *  在创建数据的时候，如果crate方法重新了，通常显示调用construct，如果字段没有赋值的情况会把defaultValue赋上：
     *  data.construct();
     */
    @Field.Enum
    @Field(displayName = "审批状态", defaultValue = "PENDING")
    @UxForm.FieldWidget(@UxWidget(invisible = "true"))
    private ApprovalStatusEnum approvalStatus;

    @Field.Date
    @Field(displayName = "审核时间")
    @UxForm.FieldWidget(@UxWidget(invisible = "true"))
    private Date auditTime;

    @Field(displayName = "审核人")
    @UxForm.FieldWidget(@UxWidget(invisible = "true"))
    private String auditUser;

    @Field.Text
    @Field(displayName = "备注")
    private String remark;
}
